//作业:第一个能不能使用promise的异步函数,封装下数据库的查询
let mysql =require('mysql');

let conn = mysql.createConnection({
    host:"localhost",
    user:"root",
    password:"root",    
    database:"123"
});
conn.connect(); 


function usePromise(sql){
    return new Promise((resolve,reject)=>{
        conn.query(sql,(err,data)=>{
            if(err!=null)reject(err);//有错误调用   
            resolve(data);//无错误调用
            conn.end();
        })
    })
}

async function doAsync(sql){
    let a = await usePromise(sql);
    console.log(a);
}

doAsync("select * from stu where stu_name = '张三'");